
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: SchemaBeanDefinitionParser.java 335 2010-02-16 17:32:13Z archie.cobbs $
 */

package org.dellroad.sidekar.spring;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

/**
 * Parses <code>&lt;sidekar:schema&gt;</code> tags.
 */
class SchemaBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

    private static final String BASE_PACKAGE_ATTRIBUTE = "base-package";

    @Override
    protected Class getBeanClass(Element element) {
        return SchemaModelFactoryBean.class;
    }

    @Override
    protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
        String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute(BASE_PACKAGE_ATTRIBUTE),
          ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        builder.addPropertyValue("basePackageNames", basePackages);
    }
}

